package com.lzhl.buildjar;

import com.lzhl.buildjar.ui.support.Cmd;
import com.lzhl.buildjar.ui.support.CmdListener;
import com.lzhl.buildjar.ui.MainUI;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Enumeration;

/**
 * @author 李柱良(@柱子的日月)
 * @date 2015/11/25
 */
public class App {

    private static ArrayList<CmdListener> cmdListeners = new ArrayList<CmdListener>();

    public static void registCmdListener(CmdListener listener) {
        cmdListeners.add(listener);
    }

    public static void removeCmdListener(CmdListener listener) {
        cmdListeners.add(listener);
    }

    public static Object fireCmd(Cmd cmd) {
        return fireCmd(cmd, null);
    }

    public static Object fireCmd(Cmd cmd, Object data) {
        for(CmdListener listener :cmdListeners) {
            Object result = listener.handleCmd(cmd, data);
            if(result != null) {
                return result;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception ignore) {
        }

//        for(Enumeration e = UIManager.getDefaults().keys(); e.hasMoreElements();) {
//            Object key = e.nextElement();
//            System.out.println(key + " = " + UIManager.get(key));
//        }
        Color color = new Color(240, 240, 240);
        UIManager.getDefaults().put("Tree.selectionBackground", new Color(51, 153, 255));
        UIManager.getDefaults().put("Button.background", Color.WHITE);
        UIManager.getDefaults().put("Panel.background", color);
        UIManager.getDefaults().put("Viewport.background", color);
        UIManager.getDefaults().put("TextField.background", Color.WHITE);
        UIManager.getDefaults().put("ToolBar.background", Color.WHITE);
        UIManager.getDefaults().put("OptionPane.background", color);
        UIManager.getDefaults().put("CheckBox.background", color);

        MainUI mainUI = new MainUI();
        mainUI.open();
    }

}
